<?php echo $header; ?>
<div id="content">
  <div class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
    <?php } ?>
  </div>
  <?php if ($error_warning) { ?>
  <div class="warning"><?php echo $error_warning; ?></div>
  <?php } ?>
  <?php if ($success) { ?>
  <div class="success"><?php echo $success; ?></div>
  <?php } ?>
  <div class="box">
    <div class="heading">
      <h1><img src="view/image/information.png" alt="" /> <?php echo $heading_title; ?></h1>
      <div class="buttons"><a onclick="$('#form').submit();" class="button"><?php echo $button_save; ?></a><a onclick="location = '<?php echo $cancel; ?>';" class="button"><?php echo $button_cancel; ?></a></div>
    </div>
    <div class="content">
      <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
        <table class="form">
          <tr>
            <td><span class="required">*</span> <?php echo $entry_name; ?></td>
            <td><input type="text" name="name" value="<?php echo $name; ?>" /></td>
          </tr>
          <tr>
            <td><?php echo $entry_attribute_group; ?></td>
            <td><select name="attribute_group_id">
                <?php foreach ($attribute_groups as $attribute_group) { ?>
                <?php if ($attribute_group['attribute_group_id'] == $attribute_group_id) { ?>
                <option value="<?php echo $attribute_group['attribute_group_id']; ?>" title="<?php echo $attribute_group['name']; ?>" selected="selected"><?php echo $attribute_group['display_name']; ?></option>
                <?php } else { ?>
                <option value="<?php echo $attribute_group['attribute_group_id']; ?>" title="<?php echo $attribute_group['name']; ?>"><?php echo $attribute_group['display_name']; ?></option>
                <?php } ?>
                <?php } ?>
              </select></td>
          </tr>
          <tr>
            <td><span class="required">*</span> <?php echo $entry_display_name; ?></td>
            <td><?php foreach ($languages as $language) { ?>
              <input type="text" name="attribute_description[<?php echo $language['language_id']; ?>][display_name]" value="<?php echo isset($attribute_description[$language['language_id']]) ? $attribute_description[$language['language_id']]['display_name'] : ''; ?>" />
              <img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /><br />
              <?php } ?></td>
          </tr>
        </table>
        <table id="attribute-value" class="list">
          <thead>
            <tr>
              <td class="left"><span class="required">*</span> <?php echo $entry_value_name; ?></td>
              <td class="left"><?php echo $entry_image; ?></td>
              <td class="left"><?php echo $entry_sort_order; ?></td>
              <td class="left"><span class="required">*</span> <?php echo $entry_value_display_name; ?></td>
              <td></td>
            </tr>
          </thead>
          <?php $attribute_value_row = 0; ?>
          <?php foreach ($attribute_values as $attribute_value) { ?>
          <tbody id="attribute-value-row<?php echo $attribute_value_row; ?>">
            <tr>
              <td class="left">
                <input type="hidden" name="attribute_value[<?php echo $attribute_value_row; ?>][attribute_value_id]" value="<?php echo $attribute_value['attribute_value_id']; ?>" />
                <input type="text" name="attribute_value[<?php echo $attribute_value_row; ?>][name]" value="<?php echo $attribute_value['name']; ?>" />
              </td>
              <td class="left"><div class="image"><img src="<?php echo $attribute_value['thumb']; ?>" alt="" id="thumb<?php echo $attribute_value_row; ?>" />
                  <input type="hidden" name="attribute_value[<?php echo $attribute_value_row; ?>][image]" value="<?php echo $attribute_value['image']; ?>" id="image<?php echo $attribute_value_row; ?>"  />
                  <br />
                  <a onclick="image_upload('image<?php echo $attribute_value_row; ?>', 'thumb<?php echo $attribute_value_row; ?>');"><?php echo $text_browse; ?></a>&nbsp;&nbsp;|&nbsp;&nbsp;<a onclick="$('#thumb<?php echo $attribute_value_row; ?>').attr('src', '<?php echo $no_image; ?>'); $('#image<?php echo $attribute_value_row; ?>').attr('value', '');"><?php echo $text_clear; ?></a></div></td>
              <td class="left"><input type="text" name="attribute_value[<?php echo $attribute_value_row; ?>][sort_order]" value="<?php echo $attribute_value['sort_order']; ?>" size="1" /></td>
              <td class="left">
                <?php foreach ($languages as $language) { ?>
                <input type="text" name="attribute_value[<?php echo $attribute_value_row; ?>][attribute_value_description][<?php echo $language['language_id']; ?>][display_name]" value="<?php echo isset($attribute_value['attribute_value_description'][$language['language_id']]) ? $attribute_value['attribute_value_description'][$language['language_id']]['display_name'] : ''; ?>" />
                <img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /><br/>
                <?php } ?></td>
              <td class="left"></td>
            </tr>
          </tbody>
          <?php $attribute_value_row++; ?>
          <?php } ?>
          <tfoot>
            <tr>
              <td colspan="4"></td>
              <td class="left"><a onclick="addAttributeValue();" class="button"><?php echo $button_add_attribute_value; ?></a></td>
            </tr>
          </tfoot>
        </table>
      </form>
    </div>
  </div>
</div>
<script type="text/javascript"><!--
var attribute_value_row = <?php echo $attribute_value_row; ?>;
function addAttributeValue() {
	html  = '<tbody id="attribute-value-row' + attribute_value_row + '">';
	html += '<tr>';	
    html += '<td class="left"><input type="text" name="attribute_value[' + attribute_value_row + '][name]" value="" /></td>';
    html += '<td class="left"><div class="image"><img src="<?php echo $no_image; ?>" alt="" id="thumb' + attribute_value_row + '" /><input type="hidden" name="attribute_value[' + attribute_value_row + '][image]" value="" id="image' + attribute_value_row + '" /><br /><a onclick="image_upload(\'image' + attribute_value_row + '\', \'thumb' + attribute_value_row + '\');"><?php echo $text_browse; ?></a>&nbsp;&nbsp;|&nbsp;&nbsp;<a onclick="$(\'#thumb' + attribute_value_row + '\').attr(\'src\', \'<?php echo $no_image; ?>\'); $(\'#image' + attribute_value_row + '\').attr(\'value\', \'\');"><?php echo $text_clear; ?></a></div></td>';
    html += '<td class="left"><input type="text" name="attribute_value[' + attribute_value_row + '][sort_order]" value="" size="1" /></td>';
	html += '<td class="left">';
	<?php foreach ($languages as $language) { ?>
	html += '<input type="text" name="attribute_value[' + attribute_value_row + '][attribute_value_description][<?php echo $language['language_id']; ?>][name]" value="" /> <img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /><br />';
    <?php } ?>
	html += '</td>';
	html += '<td class="left"><a onclick="$(\'#attribute-value-row' + attribute_value_row + '\').remove();" class="button"><?php echo $button_remove; ?></a></td>';
	html += '</tr>';	
    html += '</tbody>';
	$('#attribute-value tfoot').before(html);
	attribute_value_row++;
}
function image_upload(field, thumb) {
	$('#dialog').remove();
	$('#content').prepend('<div id="dialog" style="padding: 3px 0px 0px 0px;"><iframe src="index.php?route=common/filemanager&token=<?php echo $token; ?>&field=' + encodeURIComponent(field) + '" style="padding:0; margin: 0; display: block; width: 100%; height: 100%;" frameborder="no" scrolling="auto"></iframe></div>');
	$('#dialog').dialog({
		title: '<?php echo $text_image_manager; ?>',
		close: function (event, ui) {
			if ($('#' + field).attr('value')) {
				$.ajax({
					url: 'index.php?route=common/filemanager/image&token=<?php echo $token; ?>&image=' + encodeURIComponent($('#' + field).attr('value')),
					dataType: 'text',
					success: function(data) {
						$('#' + thumb).replaceWith('<img src="' + data + '" alt="" id="' + thumb + '" />');
					}
				});
			}
		},	
		bgiframe: false,
		width: 800,
		height: 400,
		resizable: false,
		modal: false
	});
};
//--></script>
<?php echo $footer; ?>